using System.Collections.Generic;
using OracleInternal.SqlAndPlsqlParser.LocalParsing;

namespace OracleInternal.SqlAndPlsqlParser.RuleProcessors.ODPCommands
{
	internal static class OracleMbEarleyDbLinkRuleMultiProcessors
	{
		public static OracleMbEarleyRuleMultiProcessorAddItem[] s_vRuleProcessorItems;

		static OracleMbEarleyDbLinkRuleMultiProcessors()
		{
			OracleMbEarleyRuleMultiProcessorAddItem[] array = new OracleMbEarleyRuleMultiProcessorAddItem[6];
			OracleMbEarleyRuleMultiProcessorAddItem oracleMbEarleyRuleMultiProcessorAddItem = new OracleMbEarleyRuleMultiProcessorAddItem
			{
				m_vHeadSymbol = "dblink",
				m_vRHSSymbols = new string[1]
				{
					"identifier"
				},
				m_vRuleProcessor = Process_Dblink_Identifier_Rule,
				m_vAddType = OracleMbEarleyRuleMultiProcessorAddType.SpecificRule
			};
			array[0] = oracleMbEarleyRuleMultiProcessorAddItem;
			oracleMbEarleyRuleMultiProcessorAddItem = new OracleMbEarleyRuleMultiProcessorAddItem
			{
				m_vHeadSymbol = "dblink",
				m_vRHSSymbols = new string[2]
				{
					"identifier",
					"dblink"
				},
				m_vRuleProcessor = Process_Dblink_Identifier_Dblink_Rule,
				m_vAddType = OracleMbEarleyRuleMultiProcessorAddType.SpecificRule
			};
			array[1] = oracleMbEarleyRuleMultiProcessorAddItem;
			oracleMbEarleyRuleMultiProcessorAddItem = new OracleMbEarleyRuleMultiProcessorAddItem
			{
				m_vHeadSymbol = "dblink",
				m_vRHSSymbols = new string[3]
				{
					"identifier",
					"'@'",
					"identifier"
				},
				m_vRuleProcessor = Process_Dblink_Identifier_AT_Identifier_Rule,
				m_vAddType = OracleMbEarleyRuleMultiProcessorAddType.SpecificRule
			};
			array[2] = oracleMbEarleyRuleMultiProcessorAddItem;
			oracleMbEarleyRuleMultiProcessorAddItem = new OracleMbEarleyRuleMultiProcessorAddItem
			{
				m_vHeadSymbol = "dblink",
				m_vRHSSymbols = new string[4]
				{
					"identifier",
					"dblink",
					"'@'",
					"identifier"
				},
				m_vRuleProcessor = Process_Dblink_Identifier_Dblink_AT_Identifier_Rule,
				m_vAddType = OracleMbEarleyRuleMultiProcessorAddType.SpecificRule
			};
			array[3] = oracleMbEarleyRuleMultiProcessorAddItem;
			oracleMbEarleyRuleMultiProcessorAddItem = new OracleMbEarleyRuleMultiProcessorAddItem
			{
				m_vHeadSymbol = "dblink",
				m_vRHSSymbols = new string[2]
				{
					"'.'",
					"identifier"
				},
				m_vRuleProcessor = Process_Dblink_DOT_Identifier_Rule,
				m_vAddType = OracleMbEarleyRuleMultiProcessorAddType.SpecificRule
			};
			array[4] = oracleMbEarleyRuleMultiProcessorAddItem;
			oracleMbEarleyRuleMultiProcessorAddItem = new OracleMbEarleyRuleMultiProcessorAddItem
			{
				m_vHeadSymbol = "dblink",
				m_vRHSSymbols = new string[3]
				{
					"dblink",
					"'.'",
					"identifier"
				},
				m_vRuleProcessor = Process_Dblink_Dblink_DOT_Identifier_Rule,
				m_vAddType = OracleMbEarleyRuleMultiProcessorAddType.SpecificRule
			};
			array[5] = oracleMbEarleyRuleMultiProcessorAddItem;
			s_vRuleProcessorItems = array;
		}

		public static object Process_Dblink_DblinkAlts_Rule(OracleMbEarleyParserMultiContext ctx, int ruleMatchPosition)
		{
			return OracleMbEarleyRuleMultiProcessor.ProcessNodeRules(ctx.CurrentParseNode.Children()[0], 0, -1, ctx);
		}

		public static object Process_Dblink_Identifier_Rule(OracleMbEarleyParserMultiContext ctx, int ruleMatchPosition)
		{
			return new OracleLpDbLink
			{
				Database = new OracleLpName(ctx.Tokens[ctx.CurrentParseNode.From].m_vContent)
			};
		}

		public static object Process_Dblink_Identifier_Dblink_Rule(OracleMbEarleyParserMultiContext ctx, int ruleMatchPosition)
		{
			OracleLpDbLink oracleLpDbLink = new OracleLpDbLink();
			List<ParseNode> list = ctx.CurrentParseNode.Children();
			oracleLpDbLink.Database = new OracleLpName(ctx.Tokens[list[0].From].m_vContent);
			string text = OracleMbEarleyRuleMultiProcessor.ProcessNodeRules(list[1], 0, -1, ctx) as string;
			oracleLpDbLink.Domain = new OracleLpName(text.Substring(1));
			return oracleLpDbLink;
		}

		public static object Process_Dblink_Identifier_AT_Identifier_Rule(OracleMbEarleyParserMultiContext ctx, int ruleMatchPosition)
		{
			OracleLpDbLink oracleLpDbLink = new OracleLpDbLink();
			List<ParseNode> list = ctx.CurrentParseNode.Children();
			oracleLpDbLink.Database = new OracleLpName(ctx.Tokens[list[0].From].m_vContent);
			oracleLpDbLink.ConnectionQualifier = new OracleLpName(ctx.Tokens[list[2].From].m_vContent);
			return oracleLpDbLink;
		}

		public static object Process_Dblink_Identifier_Dblink_AT_Identifier_Rule(OracleMbEarleyParserMultiContext ctx, int ruleMatchPosition)
		{
			OracleLpDbLink oracleLpDbLink = new OracleLpDbLink();
			List<ParseNode> list = ctx.CurrentParseNode.Children();
			oracleLpDbLink.Database = new OracleLpName(ctx.Tokens[list[0].From].m_vContent);
			string text = OracleMbEarleyRuleMultiProcessor.ProcessNodeRules(list[1], 0, -1, ctx) as string;
			oracleLpDbLink.Domain = new OracleLpName(text.Substring(1));
			oracleLpDbLink.ConnectionQualifier = new OracleLpName(ctx.Tokens[list[3].From].m_vContent);
			return oracleLpDbLink;
		}

		public static object Process_Dblink_DOT_Identifier_Rule(OracleMbEarleyParserMultiContext ctx, int ruleMatchPosition)
		{
			List<ParseNode> list = ctx.CurrentParseNode.Children();
			return "." + ctx.Tokens[list[1].From].m_vContent;
		}

		public static object Process_Dblink_Dblink_DOT_Identifier_Rule(OracleMbEarleyParserMultiContext ctx, int ruleMatchPosition)
		{
			List<ParseNode> list = ctx.CurrentParseNode.Children();
			return (OracleMbEarleyRuleMultiProcessor.ProcessNodeRules(list[0], 0, -1, ctx) as string) + "." + ctx.Tokens[list[2].From].m_vContent;
		}

		public static object Process_DblinkAlts_DottedName_Rule(OracleMbEarleyParserMultiContext ctx, int ruleMatchPosition)
		{
			object result = null;
			OracleMbEarleyRuleMultiProcessorTable ruleProcessorTable = ctx.RuleProcessorTable;
			ctx.RuleProcessorTable = ctx.GetRuleProcessorTable("dotted_name");
			string[] array = OracleMbEarleyRuleMultiProcessor.ProcessNodeRules(ctx.CurrentParseNode, 0, -1, ctx) as string[];
			if (array.Length > 2)
			{
				result = array[0] + "." + array[1] + "." + array[2];
			}
			else if (array.Length > 1)
			{
				result = array[0] + "." + array[1];
			}
			else if (array.Length != 0)
			{
				result = array[0];
			}
			ctx.RuleProcessorTable = ruleProcessorTable;
			return result;
		}

		public static object Process_DblinkAlts_AT_Identifier_Rule(OracleMbEarleyParserMultiContext ctx, int ruleMatchPosition)
		{
			List<ParseNode> list = ctx.CurrentParseNode.Children();
			return "@" + ctx.Tokens[list[1].From].m_vContent;
		}

		public static object Process_DblinkAlts_DottedName_AT_Identifier_Rule(OracleMbEarleyParserMultiContext ctx, int ruleMatchPosition)
		{
			string str = string.Empty;
			List<ParseNode> list = ctx.CurrentParseNode.Children();
			OracleMbEarleyRuleMultiProcessorTable ruleProcessorTable = ctx.RuleProcessorTable;
			ctx.RuleProcessorTable = ctx.GetRuleProcessorTable("dotted_name");
			string[] array = OracleMbEarleyRuleMultiProcessor.ProcessNodeRules(list[0], 0, -1, ctx) as string[];
			if (array.Length > 2)
			{
				str = array[0] + "." + array[1] + "." + array[2];
			}
			else if (array.Length > 1)
			{
				str = array[0] + "." + array[1];
			}
			else if (array.Length != 0)
			{
				str = array[0];
			}
			ctx.RuleProcessorTable = ruleProcessorTable;
			return str + "@" + ctx.Tokens[list[2].From].m_vContent;
		}
	}
}
